package com.jkl.service.drTemplateDetail;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jkl.dao.drTemplateDetail.DrTemplateDetailMapper;
import com.jkl.entity.drTemplateDetail.DrTemplateDetail;
import com.jkl.service.drTemplateDetail.inter.DrTemplateDetailServiceInterface;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class DrTemplateDetailService implements DrTemplateDetailServiceInterface {
	
	@Autowired
	private DrTemplateDetailMapper DrTemplateDetailMapper;
	//查询模板配置的上报表配
	@Override
	public List<DrTemplateDetail> selectDetailById(DrTemplateDetail drTemplateDetail) {
		
		List<DrTemplateDetail> drTemplateDetailList  = DrTemplateDetailMapper.selectDetailById(drTemplateDetail);
		if(drTemplateDetailList.size()!=0) {
			
			return drTemplateDetailList;
		}else {
			return null;
		}
		
	}
	//删除对应上报表配的所有指标再   上报表配添加指标
	@Transactional(rollbackFor=Exception.class)
	@Override
	public int saveDetailById(DrTemplateDetail drTemplateDetail) {
		
		drTemplateDetail.setIsFill("1");
		int  i=DrTemplateDetailMapper.insert(drTemplateDetail);
		if(i!=0) {
			return i;
		}else {
			return 0;
		}
		
		/*List<DrTemplateDetail> drTemplateDetailList  = DrTemplateDetailMapper.selectDetailById(drTemplateDetail);
		int z=0;
		if(drTemplateDetailList.size()!=0) {
			for (int i = 0; i < drTemplateDetailList.size(); i++) {
				z= DrTemplateDetailMapper.delete(drTemplateDetailList.get(i));
			}
		}
		if(z!=0) {
			drTemplateDetail.setIsFill("1");
			int  i=DrTemplateDetailMapper.insert(drTemplateDetail);
			if(i!=0) {
				return i;
			}
		}
			return 0;*/
		
	}
	//删除对应上报表配的所有指标
	@Override
	public int deleteDetailById(DrTemplateDetail drTemplateDetail) {
		
		List<DrTemplateDetail> drTemplateDetailList  = DrTemplateDetailMapper.selectDetailById(drTemplateDetail);
		if(drTemplateDetailList.size()!=0) {
			int z=0;
			for (int i = 0; i < drTemplateDetailList.size(); i++) {
				z= DrTemplateDetailMapper.delete(drTemplateDetailList.get(i));
			}
			return z;
		}else {
			return 0;
		}
	}

}
